(function (window, undefined) {
  function Enemy(option) {
    let ops = option instanceof Object ? option : {};
    Tank.call(this, ops);
    this.tankElements = [];
  }
  //NPC初始化渲染
  Enemy.prototype.render = function (map) {
    let enemyFrag = document.createDocumentFragment();
    for (let i = 0; i < this.tankElements.length; i++) {
      enemyFrag.appendChild(this.tankElements[i]);
    }
    map.appendChild(enemyFrag);
  };
  //批量生成多个NPC
  Enemy.prototype.createEnemy = function (map) {
    //首先生成坦克容器，以便将坦克组成块插入容器
    let enemyBox = document.createElement("div");
    enemyBox.style.width = this.width * 3 + "px";
    enemyBox.style.height = this.height * 3 + "px";
    enemyBox.style.display = "flex";
    enemyBox.style.position = this.abso;
    enemyBox.style.left = this.position.left * this.width + "px";
    enemyBox.style.top = this.position.top * this.height + "px";
    enemyBox.style.position = this.abso;
    enemyBox.style.flexWrap = "wrap";
    enemyBox.style.transform = "rotate(" + this.direction + "deg)";
    enemyBox.customBelong = this.isBelong;
    enemyBox.customDirection = this.direction;
    enemyBox.customRole = "tank";
    //循环生成各个坦克组成块
    for (let j = 0; j < this.tank.length; j++) {
      let div = document.createElement("div");
      div.style.width = this.width + "px";
      div.style.height = this.height + "px";
      div.style.backgroundColor = this.tank[j].color;
      enemyBox.appendChild(div);
    }
    this.tankElements.push(enemyBox);
    map.appendChild(enemyBox);
  };
  //NPC被玩家子弹击中时清除被击中元素
  Enemy.prototype.remove = function (map, index) {
    map.removeChild(this.tankElements[index]);
    this.tankElements.splice(index, 1);
  };
  window.Enemy = Enemy;
})(window, undefined);
